package fr.upmc.tps.mdoc.sessions;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import fr.upmc.tps.mdoc.entity.Contact;
import fr.upmc.tps.mdoc.tools.EJBUtils;

/**
 * Session Bean implementation class GestionContactBean
 */
@Stateless(mappedName = "ContactBean")
public class GestionContactBean implements GestionContactRemote {

	@PersistenceContext
	EntityManager em;

	public String coucouContact(String nomContact) {
		return "Coucou, " + nomContact;
	}

	public void addContact(String fname, String lname, String email) {
		Contact contact = new Contact();
		contact = EJBUtils.createContact(fname, lname, email);
		/*contact.setFirstName(fname);
		contact.setLastName(lname);
		contact.setEmail(email);*/
		
		em.persist(contact);
	}

	public String findContactNameById(long id) {

		Contact contact = em.find(Contact.class, id);

		return contact.getFirstName() + ", " + contact.getLastName();
	}

}
